package com.sinochem.yunlian.ship.base.rest.app;


import com.alibaba.fastjson.JSON;
import com.sinochem.yunlian.ship.api.vo.uc.UcUserInfo;
import com.sinochem.yunlian.ship.base.biz.BsFlickerActiveBiz;
import com.sinochem.yunlian.ship.base.biz.BsFlickerScreenBiz;
import com.sinochem.yunlian.ship.base.entity.BsFlickerScreen;
import com.sinochem.yunlian.ship.base.vo.request.FlickerActiveVo;
import com.sinochem.yunlian.ship.base.vo.request.FlickerScreenVo;
import com.sinochem.yunlian.ship.common.enums.ResponseCode;
import com.sinochem.yunlian.ship.common.msg.RestResponse;
import com.sinochem.yunlian.ship.common.rest.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 闪屏管理
 */
@RestController
@RequestMapping("flickerScreen")
@Slf4j
public class BsFlickerScreenController extends BaseController<BsFlickerScreenBiz,BsFlickerScreen> {

    @Autowired
    private BsFlickerScreenBiz screenBiz;

    @Autowired
    private BsFlickerActiveBiz activeBiz;

    /**
     * 闪屏图片上传
     * @return
     */
    @RequestMapping(value = "/upload",method = RequestMethod.POST)
    public RestResponse flickerScreenAdd(@RequestBody FlickerActiveVo activeVo){
        try {
            log.info("base flickerScreenAdd activeVo:{}", JSON.toJSONString(activeVo));

            List<FlickerScreenVo> vos = activeVo.getImgUrls();
            UcUserInfo ucUserInfo = activeVo.getUcUserInfo();

            if(vos==null || vos.isEmpty() ||ucUserInfo==null || ucUserInfo.getId()==null){
                return new RestResponse(ResponseCode.INVALID_PARAM);
            }
            this.activeBiz.addActive(activeVo);
            return RestResponse.success();
        }catch(Exception e){
            log.error(e.getMessage(), e);
            return new RestResponse(ResponseCode.SYS_EXCEPTION);
        }
    }

    /**
     * 闪屏图片详情
     * @return
     */
    @RequestMapping(value = "/detail",method = RequestMethod.POST)
    public RestResponse flickerScreenDetail(@RequestBody FlickerActiveVo activeVo){
        try {
            log.info("base flickerScreenDetail activeVo:{}", JSON.toJSONString(activeVo));
            return this.activeBiz.getActiveDetail(activeVo);
        }catch(Exception e){
            log.error(e.getMessage(), e);
            return new RestResponse(ResponseCode.SYS_EXCEPTION);
        }
    }


    /**
     * 闪屏图片删除
     * @return
     */
    @RequestMapping(value = "/del",method = RequestMethod.POST)
    public RestResponse flickerScreenDel(@RequestBody FlickerActiveVo activeVo){
        try {
            log.info("base flickerScreenDel activeVo:{}", JSON.toJSONString(activeVo));
            return this.activeBiz.deleteActive();
        }catch(Exception e){
            log.error(e.getMessage(), e);
            return new RestResponse(ResponseCode.SYS_EXCEPTION);
        }
    }



    /**
     * 闪屏图片查询APP
     * @return
     */
    @RequestMapping(value = "/getOne",method = RequestMethod.POST)
    public RestResponse getFlickerScreen(@RequestBody FlickerScreenVo flickerScreenVo){
        try {
            log.info("base getFlickerScreen flickerScreenVo:{}", JSON.toJSONString(flickerScreenVo));


            if(flickerScreenVo.getMobileTerminal()==null){
                return new RestResponse(ResponseCode.INVALID_PARAM);
            }
            if(StringUtils.isBlank(flickerScreenVo.getDisplaySize())){
                return new RestResponse(ResponseCode.INVALID_PARAM);
            }
            return this.activeBiz.getBsFlickerActive(flickerScreenVo);
        }catch(Exception e){
            log.error(e.getMessage(), e);
            return new RestResponse(ResponseCode.SYS_EXCEPTION);
        }
    }
}